package com.laker.autotest.api.job;


import com.laker.autotest.AutoApiTestApplication;
import com.laker.autotest.common.utils.TestNGUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;


@Component
@Slf4j
@ConditionalOnProperty(name = "easy.cronjob.enabled", havingValue = "true", matchIfMissing = true)
public class CronJob {

    @Scheduled(cron = "${easy.cronjob.cron}")
    public void testNGJob() {
        runTests();
    }

    private void runTests() {
        log.info("Starting TestNG job");
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        TestNGUtil.runWithTestNgXmlPath();
        stopWatch.stop();
        log.info("TestNG job completed ,cost {}ms", stopWatch.getTotalTimeMillis());
    }
}
